package com.shixj.ef.vo;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;

import java.io.Serializable;

/**
 * Created by shixj on 2017/9/19.
 */
public class FetchRequest implements Serializable {
    private CloseableHttpClient httpClient;
    private String originalUrl;
    private String fetchUrl;
    private boolean isRedirected = false;
    private int depth;


    public CloseableHttpClient getHttpClient() {
        return httpClient;
    }

    public void setHttpClient(CloseableHttpClient httpClient) {
        this.httpClient = httpClient;
    }


    public int getDepth() {
        return depth;
    }

    public void setDepth(int depth) {
        this.depth = depth;
    }

    public boolean getIsRedirected() {
        return isRedirected;
    }

    public void setIsRedirected(boolean redirected) {
        isRedirected = redirected;
    }

    public String getOriginalUrl() {
        return originalUrl;
    }

    public void setOriginalUrl(String originalUrl) {
        this.originalUrl = originalUrl;
    }

    public String getFetchUrl() {
        return fetchUrl;
    }

    public void setFetchUrl(String fetchUrl) {
        this.fetchUrl = fetchUrl;
    }

    public final HttpUriRequest HttpUriRequestFactory() {
        HttpUriRequest httpUriRequest = new HttpGet(this.fetchUrl);
        return httpUriRequest;
    }

    public FetchRequest() {
    }

    public FetchRequest(String originalUrl, String fetchUrl, boolean isRedirected) {
        this.originalUrl = originalUrl;
        this.fetchUrl = fetchUrl;
        this.isRedirected = isRedirected;
    }

    public FetchRequest(String originalUrl, CloseableHttpClient httpClient) {
        this.httpClient =httpClient;
        this.originalUrl = originalUrl;
        this.fetchUrl = originalUrl;
        this.depth = 0;

    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("\"originalUrl\":\"").append(originalUrl).append("\",")
                .append("\"fetchUrl\":\"").append(fetchUrl).append("\",")
                .append("\"isRedirected\":\"").append(isRedirected).append("\",")
                .append("\"depth\":\"").append(depth).append("\",");
        return String.valueOf(stringBuilder);
    }
}
